import $service from '../../../service.js';
var app = getApp();
Page({
  data: {
    doctorInfo: null,
    iconListData: [
      // {
      //   'icon_img': '../../../static/images/my_model.png',
      //   'icon_name': '个人模版',
      //   'icon_id': '6'
      // },
      {
        'icon_img': '../../../static/images/grzl_icon.png',
        'icon_name': '修改头像',
        'icon_id': '1'
      },
      {
        'icon_img': '../../../static/images/xszn_icon.png',
        'icon_name': '新手指南',
        'icon_id': '2'
      },
      {
        'icon_img': '../../../static/images/yszc_icon.png',
        'icon_name': '隐私政策',
        'icon_id': '3'
      },
      {
        'icon_img': '../../../static/images/mmgl_icon.png',
        'icon_name': '密码管理',
        'icon_id': '4'
      }, {
        'icon_img': '../../../static/images/tcdl_icon.png',
        'icon_name': '退出登录',
        'icon_id': '5'
      }
    ],
    isShowQR:false,
    doctorMap:{},
    doctorId:null
  },
  onLoad(e) {
    //加载本页面的tabBar 样式
    app.editTabBar();
    console.log(app.doctorId);
    this.getDoctorInfo()
  },
  onShow() {
    wx.hideHomeButton({})
    this.setData({
      doctorInfo: JSON.parse($service.getStore('doctorInfo'))
    })
  },
  gotopage(e) {
    var that = this
    var num = e.currentTarget.dataset.num;
    if (num == 0) {
      $service.openPage('../../user_side/personal/personal_personalset/personal_personalset?type=2')
    } else if (num == 1) {
      $service.openPage('personal_info/personal_info')
    } else if (num == 2) {
      $service.openPage('personal_prescription/personal_prescription')
    } else if (num == 3) {
      var icon_id = e.currentTarget.dataset.icon_id;
      if (icon_id == 1) {
        $service.openPage('../../user_side/personal/personal_personalset/personal_personalset?type=2')
      } else if (icon_id == 2) {
        $service.openPage('../../user_side/personal/personal_novice_guide/personal_novice_guide')
      } else if (icon_id == 3) {
        $service.openPage('../../login/agreement/agreement?type=1')
      } else if (icon_id == 4) {
        $service.openPage('../../user_side/personal/personal_changepw/personal_changepw')
      } else if (icon_id == 5) {
        wx.showModal({
          title: '温馨提示',
          content: '确定要退出登录?',
          success(res) {
            if (res.confirm) {
                //登出
                app.http.receivePatients({working: 0}).then(res => {
                    app.http.outLogin().then(res => {
                      app.webSocket.closeWebSocket();
                      $service.removeStore('userInfo');
                      $service.removeStore('miniToken');
                      $service.removeStore('doctorInfo');
                      wx.reLaunch({
                          url: '/pages/user_index/user_index'
                      })
                  }).catch(err => {
                      $service.showToast(err.msg)
                  })
                })
            }
          }
        })
      } else if (icon_id == 6) {
        $service.openPage('./personal_pre_template/personal_pre_template')
      }
    }
  },
  // 退出接诊
  receivePatients() {
    app.http.receivePatients({working: 0})
  },
  //获取医生信息
  getDoctorInfo(){
    let params ={
      id:app.doctorId
    }
    app.http.getDoctorDetail(params).then((res)=>{
      this.setData({
        doctorMap:res.data,
        doctorId:app.doctorId
      })
    })
    .catch((err)=>{
      console.log(err);
    })
  },
  //显示名片
  showQR(){
    this.setData({
      isShowQR: true
  })
  }
})